import { Store } from 'iflux2';
import { List,fromJS } from 'immutable'
import OverviewActor from './actor/overview-actor';
import { getFansInfo } from './webapi.js';
import { message } from 'antd'
//当前时间戳
const curTimeC = new Date().getTime();
//一天的时间数
const onedayTimeC = 24 * 60 * 60 * 1000;
//开始时间：昨天
let yesterdayTimeC = curTimeC - onedayTimeC;
yesterdayTimeC = new Date(yesterdayTimeC);
const end_date = `${yesterdayTimeC.getFullYear()}-${yesterdayTimeC.getMonth()+1 < 10 ? '0'+(yesterdayTimeC.getMonth()+1) : yesterdayTimeC.getMonth()+1}-${yesterdayTimeC.getDate()}`
//结束时间：一周前
let weekAgoTimeC = curTimeC - onedayTimeC * 7;
weekAgoTimeC = new Date(weekAgoTimeC);
const begin_date = `${weekAgoTimeC.getFullYear()}-${weekAgoTimeC.getMonth()+1 < 10 ? '0'+(weekAgoTimeC.getMonth()+1) : weekAgoTimeC.getMonth()+1}-${weekAgoTimeC.getDate()}`

export default class AppStore extends Store {
    bindActor () {
        return [
            new OverviewActor
        ]
    }

    constructor(props){
        super(props);
    }

    _getFansInfo = () => {
        getFansInfo({begin_date, end_date}).then(result => {
            this.dispatch('INIT_OVERVIEW_INFO', fromJS(result))
        })
    }
}